package com.dfbz.demo02_注解的解析;

import org.junit.Test;

import java.lang.annotation.Annotation;

/**
 * @author lscl
 * @version 1.0
 * @intro:
 */
public class Demo02_注解的继承 {
    /**
     * 注解的继承
     *
     * @throws Exception
     */
    @Test
    public void test1() throws Exception {

        // 获取TestComputer类的字节码对象
        Class<TestComputer> computerClass = TestComputer.class;

        // 获取TestComputer上标注的所有注解(包括TestComputer父类的注解,前提是指定的注解要被@Inherited所标注)
        Annotation[] annotations = computerClass.getAnnotations();
        for (Annotation annotation : annotations) {
            System.out.println(annotation);
        }

        System.out.println("-------------------------");

        // 获取SubTestComputer类的字节码对象
        Class<SubTestComputer> subTestComputerClass = SubTestComputer.class;

        // 获取SubTestComputer上标注的所有注解(包括SubTestComputer父类的注解,前提是指定的注解要被@Inherited所标注)
        Annotation[] subAnnotations = subTestComputerClass.getAnnotations();
        for (Annotation subAnnotation : subAnnotations) {
            System.out.println(subAnnotation);
        }
    }
}
